package org.example.movies.controller;

import com.alibaba.fastjson.JSONObject;
import org.example.movies.pojo.TUser;
import org.example.movies.service.IUserService;
import org.example.movies.service.impl.UserServiceImpl;
import org.example.movies.utils.ResponseEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UserController")
public class UserController extends HttpServlet {
    private IUserService service=new UserServiceImpl();
    private ResponseEntity resp=new ResponseEntity();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset:utf-8");
        String username = request.getParameter("username");
        String password=request.getParameter("password");
        String code = request.getParameter("code");
        boolean flag = service.checkUser(new TUser(username, password));
        if (flag){
            resp.setMsg("登录成功");
            resp.setStatus(200);
            resp.setData(flag);
        }else {
            resp.setMsg("用户名或者密码错误");
            resp.setStatus(404);
        }
        response.getWriter().println(JSONObject.toJSONString(resp));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
